/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License.You may obtain a copy of the License at
	http://www.mozilla.org/MPL/MPL-1.1.html
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import com.bourre.commands.CommandManagerFPS;
import com.bourre.commands.CommandManagerMS;
import com.bourre.data.libs.AbstractLib;
import com.bourre.data.libs.GraphicLib;
import com.bourre.events.EventType;

import fever.display.FeverStage;
import fever.utils.Stringifier;

/**
 * Sound libray.
 * 
 * <p>Use by the <strong>Fever configuration engine</strong> to load sounds 
 * libraries.
 * 
 * <p>Based on <strong>Pixlib GraphicLib</strong>.
 * 
 * @author Romain Ecarnot
 */
class fever.data.libs.SoundLib extends GraphicLib
{
	//-------------------------------------------------------------------------
	// Events definition
	//-------------------------------------------------------------------------
	
	/** Event type broadcasted when library is loaded. */
	public static var onLoadInitEVENT : EventType = AbstractLib.onLoadInitEVENT;
	
	/** Event type broadcasted to watch loading progression. */
	public static var onLoadProgressEVENT : EventType = AbstractLib.onLoadProgressEVENT;
	
	/** Event type broadcasted when a loading timout occured. */
	public static var onTimeOutEVENT : EventType = AbstractLib.onTimeOutEVENT;
	
	
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 */
	public function SoundLib( factoryName : String )
	{
		super( FeverStage.getInstance().createSoundLibTarget() );
		
		_sName = factoryName;
		_bAutoShow = false;
	}
	
	/**
	 * Triggered when swf is correctly loaded.
	 */
	public function onLoadInit() : Void
	{
		fireEventType( onLoadProgressEVENT );
		fireEventType( onLoadInitEVENT );
	}
	
	/**
	 * Stops events listening and remove movieclip target.
	 */
	public function release() : Void
	{
		getContent().removeMovieClip();

		CommandManagerMS.getInstance().remove( _dOnLoadProgress );
		CommandManagerFPS.getInstance().remove( _dOnLoadInit );
	}
	
	/**
	 * Returns string representation.
	 */
	public function toString() : String
	{
		return Stringifier.parse( this, _sName );
	}
	
	
	//-------------------------------------------------------------------------
	// Private implementation
	//-------------------------------------------------------------------------
		
	private function setName( sName : String ) : Void
	{
		_sName = sName;
	}
	
	private function show() : Void  {}
	
	private function hide() : Void {}
	
	private function isVisible() : Boolean { return false; }
	
	private function getContent() : MovieClip { return _oContent; }
	
	private function setContent(mc:MovieClip) : Void
	{
		super.setContent( mc );
	}
	
	private function getView() : MovieClip
	{
		return super.getContent();
	}
}